$(function () {
    $("#jqGrid").jqGrid({
        url: '../refundcontract/list',
        datatype: "json",
        colModel: [			
			{ label: 'id', name: 'id', index: 'id', width: 50, key: true ,hidden:true},
			{ label: '责任部门', name: 'dutyDepartment', index: 'duty_department', width: 80 }, 			
			{ label: '责任人', name: 'dutyPerson', index: 'duty_person', width: 80 }, 			
			{ label: '姓名', name: 'name', index: 'name', width: 80 }, 			
			{ label: '身份证号', name: 'idno', index: 'idno', width: 80 }, 			
			{ label: '性别', name: 'sex', index: 'sex', width: 80 }, 			
			{ label: '年龄', name: 'age', index: 'age', width: 80 }, 			
			{ label: '结算点编号', name: 'settlementId', index: 'settlement_id', width: 80 }, 			
			{ label: '结算点名称', name: 'settlementName', index: 'settlement_name', width: 80 }, 			
			{ label: '工伤是否可退', name: 'gongsType', index: 'gongs_type', width: 80 }, 			
			{ label: '工伤金额', name: 'gongsJe', index: 'gongs_je', width: 80 }, 			
			{ label: '养老是否可退', name: 'yanglType', index: 'yangl_type', width: 80 }, 			
			{ label: '养老金额', name: 'yanglJe', index: 'yangl_je', width: 80 }, 			
			{ label: '失业是否可退', name: 'shiyType', index: 'shiy_type', width: 80 }, 			
			{ label: '失业金额', name: 'shiyJe', index: 'shiy_je', width: 80 }, 			
			{ label: '医疗是否可退', name: 'yilType', index: 'yil_type', width: 80 }, 			
			{ label: '医疗金额', name: 'yilJe', index: 'yil_je', width: 80 }, 			
			{ label: '大病是否可退', name: 'dabType', index: 'dab_type', width: 80 }, 			
			{ label: '大病金额', name: 'dabJe', index: 'dab_je', width: 80 }, 			
			{ label: '公积金是否可退', name: 'gongjjType', index: 'gongjj_type', width: 80 }, 			
			{ label: '公积金金额', name: 'gongjjJe', index: 'gongjj_je', width: 80 }, 			
			{ label: '录入人', name: 'operator', index: 'operator', width: 80 }, 			
			{ label: '录入日期', name: 'operateDate', index: 'operate_date', width: 80 }, 			
			{ label: '初审人', name: 'firstTrialPerson', index: 'first_trial_person', width: 80 }, 			
			{ label: '初审日期', name: 'firstTrialDate', index: 'first_trial_date', width: 80 }, 			
			{ label: '复审人', name: 'secTrialPerson', index: 'sec_trial_person', width: 80 }, 			
			{ label: '复审日期', name: 'secTrialDate', index: 'sec_trial_date', width: 80 }, 			
			{ label: '状态', name: 'status', index: 'status', width: 80 }, 			
			{ label: '档案状态', name: 'archivesType', index: 'archives_type', width: 80 }			
        ],
		viewrecords: true,
        height: 385,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        //字段太多自动加载横轴滚动条
        shrinkToFit:false,
        autoScroll: false,
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });
});

var vm = new Vue({
	el:'#rrapp',
	data:{
		showList: true,
		title: null,
		refundContract: {}
	},
	methods: {
		query: function () {
			vm.reload();
		},
		add: function(){
			vm.showList = false;
			vm.title = "新增";
			vm.refundContract = {};
		},
		update: function (event) {
			var id = getSelectedRow();
			if(id == null){
				return ;
			}
			vm.showList = false;
            vm.title = "修改";
            
            vm.getInfo(id)
		},
		saveOrUpdate: function (event) {
			var url = vm.refundContract.id == null ? "../refundcontract/save" : "../refundcontract/update";
			$.ajax({
				type: "POST",
			    url: url,
			    contentType: "application/json",
			    data: JSON.stringify(vm.refundContract),
			    success: function(r){
			    	if(r.code === 0){
						alert('操作成功', function(index){
							vm.reload();
						});
					}else{
						alert(r.msg);
					}
				}
			});
		},
		del: function (event) {
			var ids = getSelectedRows();
			if(ids == null){
				return ;
			}
			
			confirm('确定要删除选中的记录？', function(){
				$.ajax({
					type: "POST",
				    url: "../refundcontract/delete",
				    contentType: "application/json",
				    data: JSON.stringify(ids),
				    success: function(r){
						if(r.code == 0){
							alert('操作成功', function(index){
								$("#jqGrid").trigger("reloadGrid");
							});
						}else{
							alert(r.msg);
						}
					}
				});
			});
		},
		getInfo: function(id){
			$.get("../refundcontract/info/"+id, function(r){
                vm.refundContract = r.refundContract;
            });
		},
		reload: function (event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{ 
                page:page
            }).trigger("reloadGrid");
		}
	}
});